package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.subject.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author 李川
 * @since 2020-05-14
 */
@RestController
@RequestMapping("/eduservice/subject")
//@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    //添加课程分类
    //获取到上传到的文件，读取出来
    @PostMapping("addSubject")
   public R addSubject(MultipartFile file){
        //excel文件
        eduSubjectService.saveSubject(file,eduSubjectService);
        return R.ok();
    }


    //课程分类树形显示
    @GetMapping("getAllSubject")
    public R getAllSubject(){
        //excel文件
        //泛型利用一级分类包含二级一起显示
        List<OneSubject> oneSubjects= eduSubjectService.getAllOneTwoSubject();
        return R.ok().data("list",oneSubjects);
    }

}

